package com.source.test;

/**
 * @author wangchangjie
 * @date 2025/1/16 17:42
 */
public class ConsoleTextRefresh {
    public static void main(String[] args) throws InterruptedException {
        String[] loading = {"-", "\\", "|", "/"};

        for (int i = 0; i < 100; i++) {
            // 输出内容并使用 \r 回到行首
            System.out.print("Loading: " + loading[i % loading.length] + " " + i + "%" + "\r");
            // 强制刷新输出缓冲区
//            System.out.flush();
            // 模拟耗时操作
            Thread.sleep(200);
        }
        // 确保最后的输出换行
        System.out.println("Loading complete!");
    }
}

